package test.work.service;

import java.util.Comparator;
import java.util.Scanner;

import test.work.dao.InterfaceDao;
import test.work.vo.Department;

public class DepartmentService extends ItemService<Department> {

	public DepartmentService(InterfaceDao<Department> dao, Scanner sc) {
		super(dao, sc);
	}

	@Override
	public Department inputItemInfo(boolean gubun) {
		System.out.println("학과번호 학과명");
		Department dept = new Department(sc.nextInt(), sc.next());
		if(gubun){
			System.out.println("위치");
			dept.setFloor(sc.nextInt());
		}
		return dept;
	}

	@Override
	public void prnSubMenu() {
		System.out.println("정렬[1. 학과명 2. 위치정보 3. 학과번호]");	
		switch (sc.nextInt()) {
			case 1:
				dao.prnItemList(new Comparator<Department>() {
					@Override
					public int compare(Department o1, Department o2) {
						return o1.getDeptName().hashCode()-o2.getDeptName().hashCode();
					}
				});
				
			break;
			case 2:
				dao.prnItemList(new Comparator<Department>() {
					@Override
					public int compare(Department o1, Department o2) {
						return o1.getFloor()-o2.getFloor();
					}
				});
				
				break;
			case 3:
				dao.prnItemList(null);	
				break;

			default:
				break;
		}
	}

}
